#!/bin/bash

# 安装 rpmforge
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
# 32-bit CentOS5 system
#wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
#rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm

# 安装 lighttpd 
yum install -y lighttpd
mkdir -p /styx/wwwroot/
chown -R lighttpd:lighttpd /styx/wwwroot/

# 安装 php 及相关组件
yum install -y lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-ncurses php-pear-db 

# php配置文件
sed -i '$ a\cgi.fix_pathinfo = 1' /etc/php.ini
sed -i 's/^mysql\.default_socket[ \t]*=.*/mysql\.default_socket = \/usr\/tmp\/mysql.sock/g' /etc/php.ini
sed -i 's/^mysqli\.default_socket[ \t]*=.*/mysqli\.default_socket = \/usr\/tmp\/mysql.sock/g' /etc/php.ini

chown -R lighttpd:lighttpd /var/lib/php

# lighttpd配置文件
sed -i 's/^server.document-root.*$/server.document-root = "\/styx\/wwwroot"/g' /etc/lighttpd/lighttpd.conf
sed -i 's/^#include "conf.d\/fastcgi.conf"/include "conf.d\/fastcgi.conf"/g' /etc/lighttpd/modules.conf
cat >> /etc/lighttpd/conf.d/fastcgi.conf <<EOF
fastcgi.server = ( ".php" =>
                  ( "localhost" =>
                   (
                    "socket" => "/tmp/php-fastcgi.socket",
                    "bin-path" => "/usr/bin/php-cgi"
                   )
                  )
                 )
EOF
echo it works! > /styx/wwwroot/index.html

# 启动lighttpd服务
chkconfig --levels 235 lighttpd on
/etc/init.d/lighttpd start 

